﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace NSATBPortal
{
    public partial class BaseStateHome : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void DefBaseStateGrid_RowEditing(object sender, GridViewEditEventArgs e)
        {
            int iIndex = e.NewEditIndex;

            string sRecID = DefBaseStateGrid.DataKeys[iIndex].Value.ToString();
            string sRecName = DefBaseStateGrid.Rows[iIndex].Cells[2].Text;

            Response.Redirect("BaseStateEditParameters.aspx?ID=" + sRecID.Trim() + "&Name=" + Server.UrlEncode(sRecName));
        }

        protected void DefBaseStateGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int iIndex = e.RowIndex;
            string sUserID = Request.LogonUserIdentity.Name;

            using (ATBSchemaDB objATBDB = new ATBSchemaDB())
            {
                objATBDB.DeleteDefBaseState(int.Parse(DefBaseStateGrid.DataKeys[iIndex].Value.ToString()), sUserID);
            }
            Response.Redirect(Request.RawUrl);
        }

        protected void DefBaseStateGrid_Init(object sender, EventArgs e)
        {
            DataTable dtResults;
            using (ATBSchemaDB objATBDB = new ATBSchemaDB())
            {
                dtResults = objATBDB.GetDefBaseStateList();
            }

            DefBaseStateGrid.DataSource = dtResults;
            DefBaseStateGrid.DataBind();
        }

        protected void DefBaseStateGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int iIndex = Convert.ToInt32(e.CommandArgument);
            string sRecID = DefBaseStateGrid.DataKeys[iIndex].Value.ToString();
            if (e.CommandName == "Select")
            {
                e.Handled = true;
                return;
            }
            if (e.CommandName == "New")
            {
                Response.Redirect("BaseStateCreate.aspx?Op=Copy&SourceID=" + sRecID.Trim());
                e.Handled = true;
                return;
            }

        }

    }
}